package utility;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import traveldreamEJB.Elemento;

public class InsertionInDBGenerator {

	
	private final static String[] citta;
	private final static String[] tipologie;
	private final static String[] compagnia;
	private final static String[] tipo;
	private final static String[] hotel;
	private final static String[] tipoStanza;
	private final static String descrizione="Non presente";
	private List<Elemento> elementi= new ArrayList<Elemento>();

	static {
		citta = new String[20];
		citta[0] = "Milano";
		citta[1] = "Roma";
		citta[2] = "Berlino";
		citta[3] = "Dublino";
		citta[4] = "Londra";
		citta[5] = "Catania";
		citta[6] = "Firenze";
		citta[7] = "New York";
		citta[8] = "Oslo";
		citta[9] = "Parigi";
		citta[10] = "Cannes";
		citta[11] = "Lugano";
		citta[12] = "Monaco";
		citta[13] = "Vienna";
		citta[14] = "Zurigo";
		citta[15] = "Ginevra";
		citta[16] = "Genova";
		citta[17] = "Verona";
		citta[18] = "Venezia";
		citta[19] = "Madrid";
		
		tipologie= new String[6];
		tipologie[0] = "Romantico";
		tipologie[1] = "Culturale";
		tipologie[2] = "Sportivo";
		tipologie[3] = "Relax";
		tipologie[4] = "Vegano";
		tipologie[5] = "Ladrona";
		
		tipo= new String[3];
		tipo[0]= "Escursione";
		tipo[1]= "Hotel";
		tipo[2]= "Volo";
		
		tipoStanza= new String[6];
		tipoStanza[0]= "Singola";
		tipoStanza[1]= "Doppia";
		tipoStanza[2]= "Tripla";
		tipoStanza[5]= "Quadrupla";
		tipoStanza[3]= "Suite";
		tipoStanza[4]= "Luxury";
		
		compagnia = new String[10];
		compagnia[0]= "Alitalia";
		compagnia[1]= "Air Italy";
		compagnia[2]= "BelleAir Europe";
		compagnia[3]= "Lufthansa";
		compagnia[4]= "Neos";
		compagnia[5]= "Air Berlin";
		compagnia[6]= "easyJet";
		compagnia[7]= "Ryanair";
		compagnia[8]= "Virgin America";
		compagnia[9]= "GOL";
		
		hotel = new String[13];
		hotel[0]="Sheraton";
		hotel[1]="Holiday Inn";
		hotel[2]="Hilton";
		hotel[3]="Best Western"; 
		hotel[4]="Nh Hotels"; 
		hotel[5]="Comfort Inn"; 
		hotel[6]="Accor Italia Hotels"; 
		hotel[7]="Boscolo Hotels"; 
		hotel[8]="Le Meridien"; 
		hotel[9]="Marriot"; 
		hotel[10]="Radisson"; 
		hotel[11]="Movenpick"; 
		hotel[12]="Una Hotels";
		
		
	}
	
	public InsertionInDBGenerator()
	{
		populate(elementi, 250);
	}
	
	public void populate(List<Elemento> elementi, int numeroElementi)
	{
		int idEl=0;
		int idIst=0;
		for(int numPacchetto=0; numPacchetto<20; numPacchetto++)
		{
			int tmpIst=idIst;
			int mese = (int) (1+11*Math.random());
			int inizio= (int) (1+27*Math.random());
			int fine= inizio + (int)(3+(5*Math.random()));
			
			String citta=this.getRandomCitta();
			String tipologia= this.getRandomTipologia();
			String descrizione="Da Inserire";
			String dataIn="2014-"+mese+"-"+fine+" 12:00";
			String dataOut="2014-"+mese+"-"+inizio+" 10:00";
			int numGen= 5;
			
			for(int elHotel=0; elHotel<numGen; elHotel++)
			{
				String multy=this.getRandomTipoStanza();
				String nome=this.getRandomHotel();
				descrizione=this.getRandomStelle();
				System.out.println("insert into Elemento");
				System.out.println("values ('"+idEl+"','"+citta+"','"+descrizione+"','"+multy+"','"+nome+"','"+"Hotel"+"');");
				
				System.out.println("insert into Istanza");
				System.out.println("values ('"+(idIst)+"','"+dataIn+"','"+dataOut+"','"+getRandomInt(50)+"','"+getRandomInt(500)+"','"+idEl+"');");
				idEl++;
				idIst++;
			}
			
			for(int elHotel=0; elHotel<numGen; elHotel++)
			{
				String multy=tipologia;
				String nome="Escursione "+idEl;
				descrizione="caprette ciao ciao";
				dataIn="2014-"+mese+"-"+(inizio+2)+" 15:00";
				dataOut="2014-"+mese+"-"+(inizio+2)+" 9:17";
				System.out.println("insert into Elemento");
				System.out.println("values ('"+idEl+"','"+citta+"','"+descrizione+"','"+multy+"','"+nome+"','"+"Escursione"+"');");
				
				System.out.println("insert into Istanza");
				System.out.println("values ('"+(idIst)+"','"+dataIn+"','"+dataOut+"','"+getRandomInt(50)+"','"+getRandomInt(500)+"','"+idEl+"');");
				idEl++;
				idIst++;
			}
			
			for(int elHotel=0; elHotel<numGen; elHotel++)
			{
				String multy=this.getRandomCitta();
				String nome=this.getRandomCompagnia();
				descrizione= "Aereporto X";
				int oraP= (int) (24*Math.random());
				int oraA;
				if(oraP+ (int) (1+4*Math.random())<=24)
					oraA= oraP+ (int) (1+4*Math.random());
				else
					oraA= 24-oraP+ (int) (1+4*Math.random());
				// andata
				dataIn="2014-"+mese+"-"+fine+" "+"09:59";
				dataOut="2014-"+mese+"-"+fine+" "+"06:55";
				System.out.println("insert into Elemento");
				System.out.println("values ('"+idEl+"','"+citta+"','"+descrizione+"','"+multy+"','"+nome+"','"+"Volo"+"');");
				
				System.out.println("insert into Istanza");
				System.out.println("values ('"+(idIst)+"','"+dataIn+"','"+dataOut+"','"+getRandomInt(50)+"','"+getRandomInt(500)+"','"+idEl+"');");
				idEl++;
				idIst++;
				
				// ritorno
				dataIn="2014-"+mese+"-"+inizio+" 16:32";
				dataOut="2014-"+mese+"-"+inizio+" 12:00";
				System.out.println("insert into Elemento");
				System.out.println("values ('"+idEl+"','"+multy+"','"+descrizione+"','"+citta+"','"+nome+"','"+"Volo"+"');");
				
				System.out.println("insert into Istanza");
				System.out.println("values ('"+(idIst)+"','"+dataIn+"','"+dataOut+"','"+getRandomInt(50)+"','"+getRandomInt(500)+"','"+idEl+"');");
				idEl++;
				idIst++;
			}
			
			System.out.println("insert into Pacchetto");
			System.out.println("values ('"+(numPacchetto)+"','"+citta+"','"+tipologia+"');");
			
			for(int i=tmpIst; i<idIst; i++)
			{
				System.out.println("insert into Pacchetto_has_istanza");
				System.out.println("values ('"+(numPacchetto)+"','"+i+"');");
				
			}
			
			
			
			
			
		}
	}

	private String getRandomStelle() {
		// TODO Auto-generated method stub
		int stelle= (int) (3*Math.random()+2);
		return stelle+" Stelle";
	}



	private String getRandomHotel() {
		// TODO Auto-generated method stub
		return  hotel[(int) (Math.random() * 13)] ;
	}

	private String getRandomCompagnia() {
		// TODO Auto-generated method stub
		return compagnia[(int) (Math.random() * 10)] ;
	}

	private int getRandomInt(int i) {
		// TODO Auto-generated method stub
		return (int) (Math.random()*i);
	}



	private String getRandomTipoStanza() {
		// TODO Auto-generated method stub
		return tipoStanza[(int) (Math.random() * 6)]; 
	}

	private String getRandomTipologia() {
		// TODO Auto-generated method stub
		return tipologie[(int) (Math.random() * 5)];
	}

	private String getRandomCitta() {
		// TODO Auto-generated method stub
		return citta[(int) (Math.random() * 19)]; 
	}


	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InsertionInDBGenerator prova= new InsertionInDBGenerator();
	}
	
	
}
